import { _decorator, Component, Label, Node } from 'cc';
import { Village } from '../entity/Village';
import { UserInfo } from '../common/UserInfo';
import { UIManager } from '../common/UIManager';
import { PrefabEnum } from '../common/PrefabEnum';
import { EventManager } from '../event/EventManager';
const { ccclass, property } = _decorator;

@ccclass('VillageItem')
export class VillageItem extends Component {
    @property(Label)
    villageName:Label;
    @property(Label)
    coord:Label;

    private village:Village;
    start() {
        this.node.on(Node.EventType.TOUCH_END, this.onTouchEnd, this)
    }

    setData(v:Village){
        this.village = v

        this.villageName.string = v.name
        this.coord.string = v.x + ':' + v.y
    }

    onTouchEnd(){
        EventManager.instance.emit(EventManager.EventType.SelectVillage, this.village)

        UIManager.instance.closeUI(PrefabEnum.SelectVillage)
    }
}


